package com.fc.advbox.controller.api;

import com.fc.advbox.common.ResponseJson;
import com.fc.advbox.controller.admin.BaseController;
import com.fc.advbox.entity.PubInfoEntity;
import com.fc.advbox.entity.RegionEntity;
import com.fc.advbox.service.impl.PubInfoServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Description:
 * User: Charles.Gao
 * Date: 2018-07-14 16:18
 */
@RestController
@RequestMapping("/api/pubinfo")
@Api(value="咨询API", tags={"咨询接口"})
public class PubInfoController extends BaseController {
    @Autowired
    private PubInfoServiceImpl pubInfoService;

    @ApiOperation(value = "GET -- 获取咨询列表",
            notes = " REST 方式请求。"+
                    "Request Parameter: <ul>" +
                    "<li><i>可选参数: type: , 例如：'header' 头部滚动的咨询, 'info' 其他的</i></li>" +
                    "<li><i>可选参数: limit: 每页记录数</i></li>" +
                    "<li><i>可选参数: page: 1, 当前页，默认值1</i></li>" +
                    "</ul>",
            response = ResponseJson.class,
            httpMethod = "GET",
            consumes = "application/json",
            produces = "application/json",
            code = 200
    )
    @GetMapping("/list")
    public ResponseJson doQueryList(@RequestParam(name="type", required=false) String type,
                                    @RequestParam(name="limit", required=false) Integer limit,
                                    @RequestParam(name="page", required=false) Integer page) {
        Map<String, Object> paramMap = new HashedMap();
        if(type ==null || "".equals(type)){
            paramMap.put("type","0");
        }else{
            paramMap.put("type",type);
        }
        paramMap.put("limit",limit);
        paramMap.put("page",page);
        //校对并赋值 offset和limit
        calculatePagination(paramMap);

        List<PubInfoEntity> infoList = pubInfoService.queryList(paramMap);
        return ResponseJson.success(infoList);
    }
}
